const Koa = require('koa');
const Router = require('@koa/router');

const app = new Koa();
const router = new Router();

router.get('/', (ctx, next) => {
  // ctx.router available
  ctx.type = "html"
  ctx.body = "<h1>嗯嗯</h1>"
});

app
  // 调用router.routes()来组装匹配好的路由，返回一个合并好的中间件
  // 调用router.allowedMethods()获得一个中间件，当发送了不符合的请求时，会返回 `405 Method Not Allowed` 或 `501 Not Implemented`
  .use(router.routes())
  .use(router.allowedMethods());

app.listen(9000, () => {
  console.log('koa router start')
})